import 'package:finance_app/src/entities/fixed_asset_entity.dart';
import 'package:finance_app/src/entities/ocr_attachment_entity.dart';
import 'package:finance_app/src/entities/payment_entity.dart';

fixedAssetEntityFromJson(FixedAssetEntity data, Map<String, dynamic> json) {
	if (json['date_type'] != null) {
		data.dateType = json['date_type'].toString();
	}
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['company_id'] != null) {
		data.companyId = json['company_id'] is String
				? int.tryParse(json['company_id'])
				: json['company_id'].toInt();
	}
	if (json['category_id'] != null) {
		data.categoryId = json['category_id'] is String
				? int.tryParse(json['category_id'])
				: json['category_id'].toInt();
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['number'] != null) {
		data.number = json['number'].toString();
	}
	if (json['ref_number'] != null) {
		data.refNumber = json['ref_number'].toString();
	}
	if (json['type'] != null) {
		data.type = json['type'].toString();
	}
	if (json['type_id'] != null) {
		data.typeId = json['type_id'] is String
				? int.tryParse(json['type_id'])
				: json['type_id'].toInt();
	}
	if (json['purchased_at'] != null) {
		data.purchasedAt = json['purchased_at'].toString();
	}
	if (json['category'] != null) {
		data.category = json['category'].toString();
	}
	if (json['currency_code'] != null) {
		data.currencyCode = json['currency_code'].toString();
	}
	if (json['price'] != null) {
		data.price = json['price'].toString();
	}
	if (json['total'] != null) {
		data.total = json['total'] is String
				? num.tryParse(json['total'])
				: json['total'];
	}
	if (json['book_value_after'] != null) {
		data.bookValueAfter = json['book_value_after'];
	}
	if (json['book_value'] != null) {
		data.bookValue = json['book_value'].toString();
	}
	if (json['depreciation_type'] != null) {
		data.depreciationType = json['depreciation_type'].toString();
	}
	if (json['depreciation_total'] != null) {
		data.depreciationTotal = json['depreciation_total'].toString();
	}
	if (json['lifespan'] != null) {
		data.lifespan = json['lifespan'] is String
				? int.tryParse(json['lifespan'])
				: json['lifespan'].toInt();
	}
	if (json['lifespan_used'] != null) {
		data.lifespanUsed = json['lifespan_used'] is String
				? int.tryParse(json['lifespan_used'])
				: json['lifespan_used'].toInt();
	}
	if (json['status'] != null) {
		data.status = json['status'].toString();
	}
	if (json['created_at'] != null) {
		data.createdAt = json['created_at'].toString();
	}
	if (json['updated_at'] != null) {
		data.updatedAt = json['updated_at'].toString();
	}
	if (json['asset_depreciations'] != null) {
		data.assetDepreciations = (json['asset_depreciations'] as List).map((v) => AssetDepreciation().fromJson(v)).toList();
	}
	if (json['attachments'] != null) {
		data.attachments = (json['attachments'] as List).map((v) => OcrAttachmentEntity().fromJson(v)).toList();
	}
	if (json['attachments_info'] != null) {
		data.attachmentsInfo = (json['attachments_info'] as List).map((v) => OcrAttachmentEntity().fromJson(v)).toList();
	}
	if (json['notes'] != null) {
		data.notes = json['notes'].toString();
	}
	if (json['sell_at'] != null) {
		data.sellAt = json['sell_at'].toString();
	}
	if (json['sell_currency_code'] != null) {
		data.sellCurrencyCode = json['sell_currency_code'];
	}
	if (json['sell_price'] != null) {
		data.sellPrice = json['sell_price'].toString();
	}
	if (json['sold_attachments_info'] != null) {
		data.soldAttachmentsInfo = (json['sold_attachments_info'] as List).map((v) => OcrAttachmentEntity().fromJson(v)).toList();
	}
	if (json['disposed_at'] != null) {
		data.disposedAt = json['disposed_at'].toString();
	}
	if (json['disposed_attachments_info'] != null) {
		data.disposedAttachmentsInfo = (json['disposed_attachments_info'] as List).map((v) => OcrAttachmentEntity().fromJson(v)).toList();
	}
	if (json['payments'] != null) {
		data.payments = (json['payments'] as List).map((v) => PaymentEntity().fromJson(v)).toList();
	}
	return data;
}

Map<String, dynamic> fixedAssetEntityToJson(FixedAssetEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['date_type'] = entity.dateType;
	data['id'] = entity.id;
	data['company_id'] = entity.companyId;
	data['category_id'] = entity.categoryId;
	data['name'] = entity.name;
	data['number'] = entity.number;
	data['ref_number'] = entity.refNumber;
	data['type'] = entity.type;
	data['type_id'] = entity.typeId;
	data['purchased_at'] = entity.purchasedAt;
	data['category'] = entity.category;
	data['currency_code'] = entity.currencyCode;
	data['price'] = entity.price;
	data['total'] = entity.total;
	data['book_value_after'] = entity.bookValueAfter;
	data['book_value'] = entity.bookValue;
	data['depreciation_type'] = entity.depreciationType;
	data['depreciation_total'] = entity.depreciationTotal;
	data['lifespan'] = entity.lifespan;
	data['lifespan_used'] = entity.lifespanUsed;
	data['status'] = entity.status;
	data['created_at'] = entity.createdAt;
	data['updated_at'] = entity.updatedAt;
	data['asset_depreciations'] =  entity.assetDepreciations?.map((v) => v.toJson())?.toList();
	data['attachments'] =  entity.attachments?.map((v) => v.toJson())?.toList();
	data['attachments_info'] =  entity.attachmentsInfo?.map((v) => v.toJson())?.toList();
	data['notes'] = entity.notes;
	data['sell_at'] = entity.sellAt;
	data['sell_currency_code'] = entity.sellCurrencyCode;
	data['sell_price'] = entity.sellPrice;
	data['sold_attachments_info'] =  entity.soldAttachmentsInfo?.map((v) => v.toJson())?.toList();
	data['disposed_at'] = entity.disposedAt;
	data['disposed_attachments_info'] =  entity.disposedAttachmentsInfo?.map((v) => v.toJson())?.toList();
	data['payments'] =  entity.payments?.map((v) => v.toJson())?.toList();
	return data;
}

assetDepreciationFromJson(AssetDepreciation data, Map<String, dynamic> json) {
	if (json['date_type'] != null) {
		data.dateType = json['date_type'].toString();
	}
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['company_id'] != null) {
		data.companyId = json['company_id'].toString();
	}
	if (json['asset_id'] != null) {
		data.assetId = json['asset_id'].toString();
	}
	if (json['issued_at'] != null) {
		data.issuedAt = json['issued_at'].toString();
	}
	if (json['currency_code'] != null) {
		data.currencyCode = json['currency_code'].toString();
	}
	if (json['total'] != null) {
		data.total = json['total'] is String
				? num.tryParse(json['total'])
				: json['total'];
	}
	if (json['status'] != null) {
		data.status = json['status'].toString();
	}
	if (json['created_at'] != null) {
		data.createdAt = json['created_at'].toString();
	}
	if (json['updated_at'] != null) {
		data.updatedAt = json['updated_at'].toString();
	}
	if (json['start_date'] != null) {
		data.startDate = json['start_date'].toString();
	}
	if (json['end_date'] != null) {
		data.endDate = json['end_date'].toString();
	}
	return data;
}

Map<String, dynamic> assetDepreciationToJson(AssetDepreciation entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['date_type'] = entity.dateType;
	data['id'] = entity.id;
	data['company_id'] = entity.companyId;
	data['asset_id'] = entity.assetId;
	data['issued_at'] = entity.issuedAt;
	data['currency_code'] = entity.currencyCode;
	data['total'] = entity.total;
	data['status'] = entity.status;
	data['created_at'] = entity.createdAt;
	data['updated_at'] = entity.updatedAt;
	data['start_date'] = entity.startDate;
	data['end_date'] = entity.endDate;
	return data;
}